import axios from 'axios';
import { RootThunkAction } from '..';
//  单个article内容
interface Cover {
  type: number;
}

export interface Article {
  art_id: string;
  title: string;
  aut_id: string;
  comm_count: number;
  pubdate: string;
  aut_name: string;
  is_top: number;
  cover: Cover;
}

export type ArticleAction = {
  type: 'article/getArticleList',
  payload: Article[]
}

export function getArticleList(id: number): RootThunkAction {
  return async dispatch => {
    const res = await axios.get(`http://geek.itheima.net/v1_0/articles?channel_id=${id}&timestamp=${Date.now()}`)
    dispatch({
      type: 'article/getArticleList',
      payload: res.data.data.results
    })
  }
}